package cuit.cx.groupcomment.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import cuit.cx.groupcomment.dao.PictureDAO;
import cuit.cx.groupcomment.model.Picture;

public class PictureDAOImpl extends SqlMapClientDaoSupport implements PictureDAO 
{
	private Logger log = Logger.getLogger(PictureDAOImpl.class);

 
    public PictureDAOImpl() {
        super();
    }

    public void addPic(Picture record) {
        getSqlMapClientTemplate().insert("addPic", record);
    }

  
    public int updatePic(Picture record) {
        int rows = getSqlMapClientTemplate().update("updatePic", record);
        return rows;
    }
    
    public Picture findPicById(Integer id) {
        Picture key = new Picture();
        key.setId(id);
        Picture record = (Picture) getSqlMapClientTemplate().queryForObject("findPicById", key);
        return record;
    }

   
    public int deletePic(Integer id) {
        Picture key = new Picture();
        key.setId(id);
        int rows = getSqlMapClientTemplate().delete("deletePic", key);
        return rows;
    }

	public String getMainPicUrl(Integer groupId)
	{
		return (String) getSqlMapClientTemplate().queryForObject("getMainPicUrl", groupId);

	}

	@SuppressWarnings("unchecked")
	public List<Picture> findPicByGroupId(Integer groupId)
	{
		List<Picture> result = null;
		try
		{
			result = getSqlMapClientTemplate().queryForList("getPicByGroupId", groupId);
		}
		catch (DataAccessException e)
		{
			log.error("find picture by groupId failed!", e);
		}
		return result;
	}
}